import 'package:enterprise_v6_app/app/components/custom_modele/custom_card.dart';
import 'package:enterprise_v6_app/app/core/core.dart';
import 'package:enterprise_v6_app/app/core/utils/file_util.dart';
import 'package:enterprise_v6_app/app/data/entities/application/standardiztion/standardization_entity.dart';

class StandardizationCommon {
  /// 文件卡片
  static Widget card(StandardizationEntity entity, int _) {
    return CustomCard(
      title: entity.name,
      onTap: () => FileUtils.openFile(entity.fileAddressUrl),
      titleRight: SvgPicture.asset(AppImages.icon_job_right),
      divider: CustomCard.builtinDividerWithPadding,
      content: Column(
        children: [
          buildItem('创建时间', entity.createDate),
          AppGaps.vGap10,
          buildItem('到期时间', entity.expirationDate),
          AppGaps.vGap6,
          buildItem('状态', entity.status),
        ],
      ),
    );
  }

  static Widget buildItem(String key, Object? val) {
    late final Widget valWidget;
    switch (val) {
      case final int? val:
        late final String text;
        late final Color color;
        switch (val) {
          case 0:
            text = '正常';
            color = Colors.green;
            break;
          case 1:
            text = '临期';
            color = Colors.orange;
            break;
          case 2:
            text = '到期';
            color = Colors.red;
            break;
          default:
            text = '未知';
            color = Colors.blue;
        }
        valWidget = Container(
          decoration: BoxDecoration(
            color: color,
            borderRadius: BorderRadius.circular(4.w),
          ),
          padding: EdgeInsets.symmetric(vertical: 3.w, horizontal: 7.w),
          child: Text(
            text,
            style: TextStyle(fontSize: 12.w, color: Colors.white),
            textAlign: TextAlign.end,
          ),
        );
        break;
      default:
        valWidget = Text(
          val.toString(),
          maxLines: 2,
          style: TextStyle(fontSize: 12.w, color: AppColors.font_color_black),
          textAlign: TextAlign.end,
        );
    }
    return Row(
      children: [
        Text(
          key,
          style: TextStyle(fontSize: 13.w, color: AppColors.font_color_gray),
          textAlign: TextAlign.start,
        ),
        const Spacer(),
        valWidget,
      ],
    );
  }

  static Widget buildItem2(String key, int? val) {
    late final String text;
    late final Color color;
    switch (val) {
      case 1:
        text = '合格';
        color = Colors.green;
        break;
      case 2:
        text = '不合格';
        color = Colors.red;
        break;
      default:
        text = '未知';
        color = Colors.blue;
    }
    return Row(
      children: [
        Text(
          key,
          style: TextStyle(fontSize: 13.w, color: AppColors.font_color_gray),
          textAlign: TextAlign.start,
        ),
        const Spacer(),
        Container(
          decoration: BoxDecoration(
            color: color,
            borderRadius: BorderRadius.circular(4.w),
          ),
          padding: EdgeInsets.symmetric(vertical: 3.w, horizontal: 7.w),
          child: Text(
            text,
            style: TextStyle(fontSize: 12.w, color: Colors.white),
            textAlign: TextAlign.end,
          ),
        ),
      ],
    );
  }

  static Widget buildItem3(String key, String? val) {
    late final Color color;
    switch (val) {
      case '正常':
        color = Colors.green;
        break;
      case '临期':
        color = Colors.yellow;
        break;
      case '到期':
        color = Colors.red;
        break;
      default:
        color = Colors.blue;
    }
    return Row(
      children: [
        Text(
          key,
          style: TextStyle(fontSize: 13.w, color: AppColors.font_color_gray),
          textAlign: TextAlign.start,
        ),
        const Spacer(),
        Container(
          decoration: BoxDecoration(
            color: color,
            borderRadius: BorderRadius.circular(4.w),
          ),
          padding: EdgeInsets.symmetric(vertical: 3.w, horizontal: 7.w),
          child: Text(
            val ?? '未知',
            style: TextStyle(fontSize: 12.w, color: Colors.white),
            textAlign: TextAlign.end,
          ),
        ),
      ],
    );
  }
}
